package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.Scanner;

/**
 * 编写用户注册功能
 * 程序启动后要求用户在控制台上陆续输入：用户名，密码，昵称，年龄
 * 输入完毕后，将用户输入的数据保存到数据库中
 */
public class RegDemo {
    public static void main(String[] args)throws Exception {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root");
        System.out.println("链接");
        Statement statement = connection.createStatement();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String username = sc.nextLine();
        System.out.println("请输入密码：");
        String password = sc.nextLine();
        System.out.println("请输入昵称：");
        String nickname = sc.nextLine();
        System.out.println("请输入年龄：");
        int age = Integer.parseInt(sc.nextLine());
        String sql = "INSERT INTO userinfo(username,password,nickname,age) " +
                "VALUES('"+username+"','"+password+"','"+nickname+"',"+age+")";
        PreparedStatement ps = connection.prepareStatement(sql);

        connection.close();
    }
}
